﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;

public partial class TaoBaoApi_TB_ItemProps : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            new TBCommon().BindTBShop(ddlShop);
    }
    protected void btnDown_Click(object sender, EventArgs e)
    {
        string name = ddlShop.SelectedItem.Text;
        if (name.Length == 0)
        {
            ShowMessage("请选择淘宝店铺。");
            return;
        }
        string password = ddlShop.SelectedValue;

        string errMsg = null;
        string sessionId = null;
        int ret = 0;             
        ret = new TaoBaoAPI().GetTBSessionId(Page,name, password, new TaoBaoAPI().GetAppKey(), ref errMsg, ref sessionId);
        if (ret != 0)
        {
            ShowMessage(errMsg);
            return;
        }
         
        AddItemProps(name, password, new TaoBaoAPI().GetAppKey(), new TaoBaoAPI().GetCertCode(), sessionId);
        ShowMessage("下载类目属性全部完成。");
    }
    void AddItemProps(string username, string password, string appkey, string certcode, string sessionId)
    {
        List<Model.TaoBao.TB_LEIMU> itemList = new BLL.TaoBao.TB_LEIMU().GetAllList();
        foreach (Model.TaoBao.TB_LEIMU item in itemList)
        {
            if(item.ISLEAF==1)
                if(!new TBCommon().ISHasChildByMID(item.MID))//只检索最末叶类目
                    new TB_ItemCat().GetTb_ItemPropList(username, password, appkey, certcode, sessionId, item.LMDM);
        }
    }
    void ShowMessage(string msg)
    {
        new TBCommon().ShowMessage(Page, msg);
    }
}
